var clickBodyHiddenElements=[];
function hideNeedHideElements(){
    $(clickBodyHiddenElements).hide();
    clickBodyHiddenElements=[];
}
$(document.body).click(hideNeedHideElements);
/**
 * 侧边主菜单
 */
	$('#pageSide-menu').each(function(){
		var curr=null,
		titles=$(this).find('h2');
		titles.click(function(){
			if(!$(this).hasClass('on')){
				if(curr){
					curr.removeClass('on');
					curr.next('ul').slideUp();
				}
				curr=$(this);
				curr.addClass('on');
				curr.next('ul').slideDown();
			
			}else{
				curr.removeClass('on');
				curr.next('ul').slideUp();
				curr=$(this);
			}
		});
		titles.eq(0).click();
		
	});

 /**
  * 添加客户下拉菜单
  */
	var list=$('#pageSide-advanced-menu>li');
	var curr=null;
	$('#pageSide-advanced-menu .control-menu').click(function(event){
		var p=$(this).parent('li');
		//
		list.not(p[0]).removeClass('Item-on'); 
		p.toggleClass('Item-on');
		event.stopPropagation();
	});
	$(document.body).click(function(){
		list.removeClass('Item-on');
	});
	//点击空白处也要隐藏菜单

 /**
  * 高级搜索
  */
	
	//高级搜索内容区域
	 //$('#search-advanced').KandyTabs({trigger:'click',classes:'search-advanced'});
	 $('#search-advanced').each(function(){
		 var dts=$(this).children('dt'),
			 dds=$(this).children('dd');

		 dts.addClass('DT');
		 dds.addClass('DD');
		 dts.click(function(){
			 var dd=$(this).next('dd');
			 if(dd.is(':visible')){
				 $(this).removeClass('DT-Show');
				 dd.hide();
			 }else{
				 dd.show();
				 $(this).addClass('DT-Show');
			 }
		 }).eq(0).click();

	 });
	 var searchs=$('#pageSearch').children('.Advanced-Search');

	//control-advanced-search
	var flag_search_show=false;
	function hideAdvancedSearch(){
	    $('#pageSearch').hide();
		$('#pageMain').css('left','226px');
		flag_search_show=false;
	}
	function showAdvancedSearch(){
	   $('#pageMain').css('left','527px');
	   $('#pageSearch').show();
	   flag_search_show=true;
	}

	function toggleSearchShow(event){
		if(flag_search_show){
			hideAdvancedSearch();
		}else{
			showAdvancedSearch();
			searchs.hide();
		    $('#Search_client').show();
		}
		event.preventDefault();
		event.stopPropagation();
	}
	$('#control-advanced-search, #control-search-client, #control-search-order ').click(toggleSearchShow);
	$('#control-hideAdvancedSearch, #pageSide').click(hideAdvancedSearch);

//高级搜索区域menu bar
$('#control-common-search-client').click(function(event){
	hideNeedHideElements();
	var con=$('#common-search-client');
	if(con.is(':visible')){
		con.hide(); 
		return;
	}
	var offset = $(this).offset();
	offset.top+=$(this).outerHeight();
	con.css({top:offset.top+5 }).show();
	
	clickBodyHiddenElements.push(con[0]);
	event.stopPropagation();
});

$('#control-common-search-client-save').click(function(event){
	hideNeedHideElements();
	var con=$('#common-search-client-save');
	if(con.is(':visible')){
		con.hide(); 
		return;
	}
	var offset = $(this).offset();
	offset.left=(offset.left+$(this).innerWidth()-con.innerWidth() )
	offset.top+=$(this).outerHeight();
	con.css({ top:offset.top+5 }).show();
	clickBodyHiddenElements.push(con[0]);
	event.stopPropagation();
});